﻿CREATE VIEW [dbo].[ASMS_V_Customer]
	AS 
SELECT 
	C.* ,
	MDICountry.Name as CountryName,
	MDIProvince.Name as ProvinceName,
	MDICity.Name as CityName,
	MDIDistrict.Name as DistrictName,
	MCT.Name as TypeName,
	S.[Name] as SalesManagerName
FROM ASMS_Customer as C
	left join ASMS_Staff as S on S.Id = C.SalesManagerId
	left join [ASMS_MasterDataItem] as MDICountry on MDICountry.Code = C.Country
	left join [ASMS_MasterDataItem] as MDIProvince on MDIProvince.Code = C.Province
	left join [ASMS_MasterDataItem] as MDICity on MDICity.Code = C.City
	left join [ASMS_MasterDataItem] as MDIDistrict on MDIDistrict.Code = C.District
	left join [ASMS_MasterDataItem] as MCT on MCT.Code = C.[Type]
